<?include "conninfo.php";//connect to database
$myfile="rainfall1.txt";//name of file

$filelink=fopen($myfile,"r")or die("Unable to open file!");

$data=fread($filelink,filesize($myfile));//read entire file
		
fclose($filelink);//close the file

$incoming=array();
$incoming=explode(chr(13),$data);

$length=sizeof($incoming);//how big is the array?

$tempdata=array();

for($x=0;$x<$length;$x++)
{
$incoming[$x]=trim($incoming[$x]);//clean off the linebreak
$tempdata=explode(" ",$incoming[$x]);//split current line of data that has been read into 3
$timeofreading=$tempdata[1]." ".$tempdata[2];//stick datestamp back together in one variable ($timeofreading)
$rainfall=trim($tempdata[0]);//rainfall reading

$query="INSERT INTO rainfalldata(mydata,thedate,sensor)
VALUES($rainfall,'$timeofreading',1)";

$result=mysqli_query($link,$query);
}
echo "Data has been transferred";





?>